<?php

$basedir = dirname(__FILE__);

require_once $basedir . '/../../../classes/minime/user.php';

class Minime_UserTest extends PHPUnit_Framework_TestCase {
    
    public function testConstructorOfMinimeUserObject() {
        
        $arrayUser['uri'] = "http://www.google.com/super/special?example=yes&silly=true";
        $arrayUser['name'] = "Pamela Anderson";
        $arrayUser['jid'] = "pamela@boobs.com";
        $arrayUser['privatekey'] = "RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=";
        $arrayUser['publickey'] = "RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.";
        $arrayUser['title'] = "This is a great stuff";
        $arrayUser['subtitle'] = "hopefully.";
        $arrayUser['logo'] = "http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png";
        
        $object = Minime_User::buildFromArray($arrayUser);
        $this->assertEquals("Minime_User", get_class($object));
    }
    
    public function testCreationOfMinimeUserObjectFromRawXml() {
        $rawXML = '<minimeuser>
  <name>Tuomas Koski</name>
  <uri>http://lobstermosnter.org/minime</uri>
  <jid>koski@lobstermonster.org</jid>
  <encoded-privatekey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=</encoded-privatekey>
  <encoded-publickey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.</encoded-publickey>
  <title>My timeline!</title>
  <subtitle>My timeline provided by minime mini system. Minimalic!</subtitle>
  <logo>http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png</logo>
</minimeuser>';
        
        $user = Minime_User::buildFromRawXML($rawXML);
        $this->assertEquals("Tuomas Koski", $user->getName());
        $this->assertEquals("http://lobstermosnter.org/minime", $user->getUri());
        $this->assertEquals("koski", $user->getNode());
        $this->assertEquals("lobstermonster.org", $user->getDomain());        
        $this->assertEquals("RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=", $user->getEncodedPrivateKey());
        $this->assertEquals("RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.", $user->getEncodedPublicKey());
        
    }
    
    public function testCreationOfXmlFromUserObjecUsingRawXml() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<minimeuser>
  <name>Tuomas Koski</name>
  <jid>koski@lobstermonster.org</jid>
  <uri>http://lobstermosnter.org/minime</uri>
  <encoded-privatekey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=</encoded-privatekey>
  <encoded-publickey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.</encoded-publickey>
  <title>This is a cool place!</title>
  <subtitle></subtitle>
  <logo></logo>
</minimeuser>';
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<minimeuser>
  <uri>http://lobstermosnter.org/minime</uri>
  <jid>koski@lobstermonster.org</jid>
  <name>Tuomas Koski</name>
  <encoded-privatekey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=</encoded-privatekey>
  <encoded-publickey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.</encoded-publickey>
  <title>This is a cool place!</title>
  <subtitle></subtitle>
  <logo></logo>
</minimeuser>
';
        
        $user = Minime_User::buildFromRawXML($rawXML);
        $this->assertEquals($expected, $user->asXML());
    }
    
    public function testCreationOfXmlFromUserObjecUsingVaribles() {
        
        $arrayUser['uri'] = 'http://lobstermosnter.org/minime';
        $arrayUser['name'] = "Tuomas Koski";
        $arrayUser['jid'] = "koski@beer.com";
        $arrayUser['privatekey'] = "RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=";
        $arrayUser['publickey'] = "RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.";
        $arrayUser['title'] = "Tuomas' Super Blog!";
        $arrayUser['subtitle'] = "This is where all the magic happens!";
        $arrayUser['logo'] = "http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png";
        
        $user = Minime_User::buildFromArray($arrayUser);
        //$user->setLogo('http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png');
        
//        $user = new Minime_User();
//        $user->setUri('http://lobstermosnter.org/minime');
//        $user->setUsername('koski');
//        $user->setName('Tuomas Koski');
//        $user->setEncodedPrivateKey("RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=");
//        $user->setEncodedPublicKey("RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.");
//        $user->setTitle('Tuomas\' Super Blog!');
//        $user->setSubtitle('This is where all the magic happens!');
//        $user->setLogo('http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png');
//        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<minimeuser>
  <uri>http://lobstermosnter.org/minime</uri>
  <jid>koski@beer.com</jid>
  <name>Tuomas Koski</name>
  <encoded-privatekey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.F2Hw70gSFFcwapgZdOLw6MSkL81sS6a1LXNKSFzm4aC_eFryH9zMFddVvJzFJoksBFf7Nmt8Ua4aRgqUaV-bteF2LWWud4uZz5v89pwqmgp6JGDbGfHjwSJvIlucB5IlKq3lIluNWx5v0IPsKpPdCMmaTIP7ckmJ4Ta9lqpAB0M=</encoded-privatekey>
  <encoded-publickey>RSA.iBamjotepBpArJxeMCM7y8qv3DUQbV_96XscmnBEiIi0LAXr_Ur3HTBnNnLqq7hDU_3xnkfs7f4cq9hz2mXaDO9xk-QLe3lmehTjMLQGqkZCoti3SQ0yVUUjqaJRA8JOXrq2LQqsYdljxyShZ99_EzGQ383xe2aMrH1hq15nFFk=.AQAB.</encoded-publickey>
  <title>Tuomas\' Super Blog!</title>
  <subtitle>This is where all the magic happens!</subtitle>
  <logo>http://media.buddycloud.com/channel/54x54/buddycloud.com/koski.png</logo>
</minimeuser>
';
        $this->assertEquals($expected, $user->asXML());
    }  
}